package com.adv.ems.model.vo;

import com.adv.ems.db.entity.*;
import com.adv.ems.utils.EmsUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

@Data
public class BaseMeterVO {
    private List<BaseMeterVO.Info> list;

    public BaseMeterVO() {
        this.list = new ArrayList<BaseMeterVO.Info>();
    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Info extends MeterDO {
        private String instituteName;
        private String buildingName;
        private String energyName;
        private String itemName;
        private String itemOneName;
        private String itemTwoName;


        public Info(MeterDO m, InstituteInfoDO instituteInfoDO, BuildingInfoDO building, EnergyInfoDO energyInfo, ItemInfoDO itemInfo, ItemOneInfoDO itemOneInfo, ItemTwoInfoDO itemTwoInfo, String acceptLanguage) {
            BeanUtils.copyProperties(m, this);
            if (instituteInfoDO != null) {
                this.setInstituteName(EmsUtil.getNameInfo(instituteInfoDO.getNameInfo(), acceptLanguage).getShortName());
            }
            if (building != null) {
                this.setBuildingName(EmsUtil.getNameInfo(building.getNameInfo(), acceptLanguage).getShortName());
            }
            if (energyInfo != null) {
                this.setEnergyName(EmsUtil.multilingual(energyInfo.getNameInfo(), acceptLanguage));
            }
            if (itemInfo != null) {
                this.setItemName(EmsUtil.multilingual(itemInfo.getNameInfo(), acceptLanguage));
            }
            if (itemOneInfo != null) {
                this.setItemOneName(EmsUtil.multilingual(itemOneInfo.getNameInfo(), acceptLanguage));
            }
            if (itemTwoInfo != null) {
                this.setItemTwoName(EmsUtil.multilingual(itemTwoInfo.getNameInfo(), acceptLanguage));
            }
        }
    }
}
